import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    username: sessionStorage.getItem('name'),  // 保存当前登录用户
    phone: sessionStorage.getItem('phone'),  // 保存当前登录用户的phone
    uid: sessionStorage.getItem('uid'),  // 保存当前登录用户的id
    pic: sessionStorage.getItem('pic'),  // 保存当前登录用户的头像
  },
  getters: {
  },
  mutations: {
    // state就是vuex.state   newName是传递过来的新用户名参数
    updateName(state,newName){
      state.username = newName
      // 将username存入sessionStorage
      window.sessionStorage.setItem('name',newName)
    },
    updateUid(state,newUid){
      state.uid = newUid
      // 将uid存入sessionStorage
      window.sessionStorage.setItem('uid',newUid)
    },
    updatePhone(state,newPhone){
      state.phone = newPhone
      // 将phone存入sessionStorage
      window.sessionStorage.setItem('phone',newPhone)
    },
    updatePic(state,newPic){
      state.pic = newPic
      // 将pic存入sessionStorage
      window.sessionStorage.setItem('pic',newPic)
    },

    // 收藏信息
    // updateColor2(state,newColor2){
    //   state.color2 = newColor2
    //   // 将color2存入sessionStorage
    //   window.sessionStorage.setItem('color2',newColor2)
    // }
  },
  actions: {
  },
  modules: {
  }
})
